package everyday;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/7/13 9:28
 * 2544. 交替数字和
 * https://leetcode.cn/problems/alternating-digit-sum/description/
 */
public class Solution2544 {

    public int alternateDigitSum(int n) {
        int sign = 1;  // 记录符号
        int res = 0;  // 记录结果
        while (n > 0) {
            int num = n % 10;
            res += num * sign;
            sign = -sign;
            n /= 10;
        }
        return -sign * res;
    }
}
